package com.example.xm.adapter.HomeAdapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.example.xm.R;
import com.example.xm.base.BaseAdapter;
import com.example.xm.bean.HomeBean.HomeRecommendBean;
import com.example.xm.ui.home.activity.ImageActivity;

import java.util.ArrayList;
import java.util.List;

public class CommentAdapter extends BaseAdapter {

    public CommentAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected int getLayout() {
        return R.layout.activity_detail_item;
    }

    @SuppressLint({"NewApi", "SetTextI18n"})
    @Override
    protected void bindData(BaseViewHolder viewHolder, Object o) {
        ImageView img = (ImageView) viewHolder.getViewById(R.id.iv_head_rlv);
        ImageView lv = (ImageView) viewHolder.getViewById(R.id.iv_lv);
        TextView title = (TextView) viewHolder.getViewById(R.id.tv_title_rlv);
        TextView zan = (TextView) viewHolder.getViewById(R.id.tv_zan);
        TextView detail = (TextView) viewHolder.getViewById(R.id.tv_detail);
        TextView date = (TextView) viewHolder.getViewById(R.id.tv_detail);
        HomeRecommendBean.DataBean.CommentsBean.AllCommentsBean bean = (HomeRecommendBean.DataBean.CommentsBean.AllCommentsBean) o;
        detail.setText(bean.getComment());
        title.setText(bean.getNickName());
        RequestOptions requestOptions = new RequestOptions().circleCrop();
        Glide.with(context).load(bean.getHeadUrl()).apply(requestOptions).into(img);
        zan.setText(bean.getLikeNumber() + "");
        date.setText(bean.getCreateTime() + "");
        int level = bean.getLevel();
        if (level == 1) {
            lv.setImageDrawable(context.getDrawable(R.mipmap.lv1));
        } else if (level == 2) {
            lv.setImageDrawable(context.getDrawable(R.mipmap.lv2));
        } else if (level == 3) {
            lv.setImageDrawable(context.getDrawable(R.mipmap.lv3));
        } else if (level == 4) {
            lv.setImageDrawable(context.getDrawable(R.mipmap.lv4));
        } else if (level == 5) {
            lv.setImageDrawable(context.getDrawable(R.mipmap.lv5));
        } else if (level == 6) {
            lv.setImageDrawable(context.getDrawable(R.mipmap.lv6));
        } else if (level == 7) {
            lv.setImageDrawable(context.getDrawable(R.mipmap.lv7));
        } else if (level == 8) {
            lv.setImageDrawable(context.getDrawable(R.mipmap.lv8));
        } else if (level == 9) {
            lv.setImageDrawable(context.getDrawable(R.mipmap.lv9));
        } else {
            lv.setImageDrawable(context.getDrawable(R.mipmap.lv10));
        }
        //头像大图
        ArrayList<String> imgss = new ArrayList<>();
        imgss.add(bean.getHeadUrl());
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ImageActivity.class);
                intent.putExtra("postion", 1);
                intent.putExtra("list",imgss);
                context.startActivity(intent);
            }
        });
    }
}
